home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-03-20 | 31.8 KB | 991 lines | [TEXT/MPS ] |
- /*----------------------------------------------------------------------------------------------
- FILENAME
-
- LaserSCIntf.c
-
- DESCRIPTION
-
- This file contains routines for invoking commands within the command set provided by the
- LaserWriter SC and IISC. Routines within this file utilize the WriteData and CheckStatus
- printing messages to in order to communicate with the printer. The actual SCSI code used to
- perform the I/O to the printer is implemented in the SD_WriteData, SD_CheckStatus and
- SD_GetDeviceStatus routines within the UniversalMessageIntf.c file. The routines in this
- file provide a "higher level" interface to the SC/IISC by hiding the details of the SC/IISC
- commands and their implementation.
-
- COPYRIGHT
-
- Copyright Apple Computer, Inc. 1989-1992
- All rights reserved.
-
- ROUTINES IN THIS MODULE:
-
- interface routines:
- LaserSC_OpenConn()
- LaserSC_GetDeviceStatus()
- LaserSC_ResetDevice()
- LaserSC_GetSenseData()
- LaserSC_SetPageMargins()
- LaserSC_SetPageDimensions()
- LaserSC_ClearBits()
- LaserSC_DrawBits()
- LaserSC_PrintPage()
- LaserSC_QueryPrinter()
- LaserSC_SetBuffandFeedMode()
- LaserSC_GetTimeoutForSCSICmnd()
-
-
- -----------------------------------------------------------------------------------------------*/
-
- // Include the standard Mac header files
- #include "MacIncludes.h"
-
- // Include the new QuickDraw GX graphics header files
- #include <GXGraphics.h>
- #include <GraphicsLibraries.h>
- #include <GXMath.h>
-
- // Include the required Printing Manager header files
- #include <GXPrinting.h>
- #include <GXPrinterDrivers.h>
- #include <Collections.h>
- #include <GXMessages.h>
-
- #include <GXExceptions.h>
-
- // Include the internal driver constants and types used by this module
- #include "LaserSCResources.h"
- #include "UniversalMessageIntf.h"
- #include "LaserSCIntf.h"
-
-
- /*********************************************************************************
- * CONSTANTS *
- *********************************************************************************/
-
- // Miscellaneous constants
- enum
- {
- minSCSICmndSz = 5, // Min. # of inquiry bytes returned by all SCSI devices
-
- kMaxRowBytes = 304, // max rowBytes supported by SC printer
-
- kPrintFromSCRam = 0x0080, // Bit in the SCSI Print page command that sets the "print from printer RAM" attribute
- kPrintContinuous = 0x0040, // Bit in the SCSI Print page command that sets the "print a 8 ppm rate" attribute
- kClearWhilePrinting = 0x0020, // Bit in the SCSI Print page command that sets the "clear page while page is being printed" attribute
-
- kBuffered = 2, // These constants are used to set the manual feed and buffered mode of the printer
- kFeed = 4,
- kManual = 0x01,
- kBufferedMode = 0x10
- };
-
-
- /*********************************************************************************
- * TYPES *
- *********************************************************************************/
-
- // SCSICommData - structure that defines the layout of the SCSI version of the 'comm' resource
-
- typedef struct
- {
- ResType commType; // communications type ('sPTL')
-
- ProcPtr releaseDevice; // Pointer to C routine that can release SCSI device,
- // can be nil (N/A for this driver)
- short scsiIOAttributes; // SCSI I/O attributes applicable to data xfers (N/A for this driver)
- short *statusByte; // Location to store status byte from data xfer operation,
- // can be nil (N/A for this driver)
- short scsiBus; // Number of scsi bus to which device is attached (0 = motherboard; applies to open connection call only). (N/A for this driver)
- short deviceNum; // Number of scsi device to open connection to (applies to open connection call only). (N/A for this driver)
- long bytesPerChunk; // 0 => ignored; > 0 => break data transfer into chunks
- // of this size (at SCSI TIB level). (N/A for this driver)
- ProcPtr acquireDevice; // Pointer to C routine that can acquire SCSI device,
- // nil == use info below in standard routine (N/A for this driver)
- short deviceKind; // device kind to look for in reponse
- short minLength; // minimum additional data to get in response
- short offsetStart; // offset from start of returned data to look at (N/A for this driver)
- Str255 searchString; // string to search for in the response
- } SCSICommData,
- *SCSICommDataPtr,
- **SCSICommDataHdl;
-
-
- /*********************************************************************************
- * DEFINES *
- *********************************************************************************/
-
- // Useful defines for doing I/O to the printer
-
- #define SendSCSICmnd(pCmnd, cmndSize) Send_GXWriteData(pCmnd, cmndSize)
- #define GetDataFromPrinter(inputBuff, numToGet, scsiChunkSize) Send_GXGetDeviceStatus(nil, scsiChunkSize, inputBuff, numToGet, "\p")
- #define SendDataToPrinter(outputBuff, numToSend, scsiChunkSize) Send_GXCheckStatus(outputBuff, numToSend, scsiChunkSize, kDrvrCreatorType)
- #define GetLastSCSIStatus(lastStatus) Send_GXGetDeviceStatus(nil, 0, nil, lastStatus, "\p")
-
-
- /***************************************************************************************
- * INTERNAL ROUTINES *
- ***************************************************************************************/
-
- /********************************************************************************************
-
- EqlByteStream
- function:
- EqlByteStream compares two byte streams, for a specified number of characters, to
- determine if they are equal.
-
- parameters:
- stream1 Pointer to first byte stream
- stream2 Pointer to second byte stream
- bytesToChk Number of bytes to compare in the two streams
-
- returns:
- EqlByteStream Returns true if byte strings equal; false otherwise
-
- ********************************************************************************************/
- Boolean EqlByteStream(Ptr stream1, Ptr stream2, short bytesToChk)
- {
- Boolean theyMatch = true;
-
- // Assume streams will match initially
-
- for (; bytesToChk > 0; --bytesToChk)
- {
- if (*stream1++ != *stream2++) // T => Streams don't match
- {
- theyMatch = false;
- break;
- }
- }
-
- return(theyMatch);
- }
- /* EqlByteStream */
-
-
- /********************************************************************************************
-
- DeviceIsSCPrinter
- function:
- DeviceIsSCPrinter queries the specified SCSI device to determine if it's a
- SC/IISC printer. If is, it returns true; otherwise it returns false. The
- device to query is specified by the
-
- parameters:
- scsiCommData Handle to the 'comm' resource in the target DTP file
-
- returns:
- Boolean Returns true if selected device is a SC/IISC printer; false otherwise
-
- ********************************************************************************************/
- Boolean DeviceIsSCPrinter(SCSICommDataHdl scsiCommData)
- {
- OSErr anErr;
- SCInquiryData queryData;
- Boolean isOurPrinter = false;
- short amntInqData;
-
- // Query the device to determine if it's a printer
-
- anErr = LaserSC_QueryPrinter(&queryData, minSCSICmndSz);
- require(anErr == noErr, QueryPrinterFails1);
-
- // Device responded. Now see how much more data we can read from the device
-
- amntInqData = queryData.additionalLength + minSCSICmndSz;
- if (amntInqData > sizeof(SCInquiryData)) // T => Only read max. bytes query record can hold
- amntInqData = sizeof(SCInquiryData);
-
- // Now read as much of the query data as we can from the device
-
- anErr = LaserSC_QueryPrinter(&queryData, amntInqData);
- require(anErr == noErr, QueryPrinterFails2);
-
- // Finally we can determine if the device is an SC/IISC
- {
- SCSICommDataPtr pCommData = *scsiCommData;
-
- if (queryData.peripheralType == pCommData->deviceKind) // T => Responding device is a printer
- {
- if (queryData.additionalLength >= pCommData->minLength) // T => Device gave us enough additional query data
- {
- // Do the device product names match?
- isOurPrinter = EqlByteStream( ((Ptr) &queryData) + pCommData->offsetStart,
- (Ptr)(&pCommData->searchString[1]),
- pCommData->searchString[0]);
- }
- }
- }
-
-
- /******* Clean-up *******/
-
- QueryPrinterFails2:
- QueryPrinterFails1:
- return(isOurPrinter);
- }
- /* DeviceIsSCPrinter */
-
-
- /***************************************************************************************
- * INTERFACE ROUTINES *
- ***************************************************************************************/
-
- /********************************************************************************************
-
- LaserSC_OpenConnection
- function:
- This routine establishes a connection to the LaserWriter SC/IISC referenced
- in the current Job. To determine which SCSI device number to use, we
- extract the 'comm' resource from the target Desktop Printer file and use
- the deviceNum field in the SCSICommData handle that is returned.
-
- If LaserSC_OpenConnection is successful, the client should always call
- LaserSC_SetPageMargins and LaserSC_SetPageDimensions to ensure the printer's
- page buffer is properly initialized. Failure to call these routines could
- reduce the life of the printing engine.
-
- parameters:
- None
-
- returns:
- OSErr
-
- ********************************************************************************************/
- OSErr LaserSC_OpenConnection()
- {
- OSErr anErr;
- SpecGlobalsHdl hGlobals = GetMessageHandlerInstanceContext();
- Str31 printerName;
- SCSICommDataHdl scsiCommData;
-
- // Get the name of the target desktop printer
-
- GXGetPrinterName(GXGetJobOutputPrinter(GXGetJob()), printerName);
-
- // Now extract the SCSI 'comm' resource to get at the device number
-
- anErr = GXFetchDTPData(printerName, gxDeviceCommunicationsType, gxDeviceCommunicationsID, (Handle *) &scsiCommData);
- require(anErr == noErr, FetchDTPData);
-
- // Set the deviceNum field in the globals to be the device we want to access
- (*hGlobals)->deviceNum = (*scsiCommData)->deviceNum;
-
- // Is the target device a LaserWriter SC/IISC printer?
- if ( !DeviceIsSCPrinter(scsiCommData) )
- anErr = gxAioCantFindDevice;
-
- // Dump the resource handle we fetched
- DisposeHandle((Handle) scsiCommData);
-
- check(anErr == noErr);
-
-
- /******* Clean-up *******/
-
- FetchDTPData:
- return(anErr);
- }
- /* LaserSC_OpenConnection */
-
-
- /********************************************************************************************
-
- LaserSC_GetDeviceStatus
- function:
- LaserSC_GetDeviceStatus queries the printer to determine if it's ready to print.
- It returns a deviceStatus parameter which indicates the current readiness state of
- the device (kGoodCondition, kCheckCondition, or kBusy). If the device is in a
- check condition state, the client can call LaserSC_GetSenseData to determine the
- exact reason why the device isn't ready.
-
- parameters:
- deviceStatus Returns the current status of the device
-
- returns:
- OSErr
-
- ********************************************************************************************/
- OSErr LaserSC_GetDeviceStatus(short *deviceStatus)
- {
- OSErr anErr;
- short scsiCommand[3];
- long cmndSz;
- long lastStatus;
-
- // Set up the test for ready SCSI command to be sent to the printer
-
- scsiCommand[0] = kSCPrinterReady;
- scsiCommand[1] = kSCReserved;
- scsiCommand[2] = kSCReserved;
- cmndSz = 6;
-
- // Send the SCSI command to the device
-
- anErr = SendSCSICmnd((Ptr) scsiCommand, cmndSz);
- require(anErr == noErr, SendSCSICmndFails);
-
- // Now fetch the last status of the device
-
- anErr = GetLastSCSIStatus(&lastStatus);
- require(anErr == noErr, GetLastSCSIStatusFails);
-
- // Return the last status
- *deviceStatus = lastStatus;
-
-
- /******* Clean-up *******/
-
- GetLastSCSIStatusFails:
- SendSCSICmndFails:
- return(anErr);
- }
- /* LaserSC_GetDeviceStatus */
-
-
- /********************************************************************************************
-
- LaserSC_ResetDevice
- function:
- LaserSC_ResetDevice will reset the LaserWriter SC/IISC to its default power-up
- state (without performing the power-up diagnostics).
-
- parameters:
- none
-
- returns:
- OSErr
-
- ********************************************************************************************/
- OSErr LaserSC_ResetDevice()
- {
- OSErr anErr;
- short scsiCommand[3];
- long cmndSz;
-
- // Set up the reset SCSI command to be sent to the printer
-
- scsiCommand[0] = kSCResetPrinter;
- scsiCommand[1] = kSCReserved;
- scsiCommand[2] = kSCReserved;
- cmndSz = 6;
-
- // Send the SCSI command to the device
-
- anErr = SendSCSICmnd((Ptr) scsiCommand, cmndSz);
- require(anErr == noErr, SendSCSICmndFails);
-
-
- /******* Clean-up *******/
-
- SendSCSICmndFails:
- return(anErr);
- }
- /* LaserSC_ResetDevice */
-
-
- /********************************************************************************************
-
- LaserSC_GetSenseData
- function:
- LaserSC_GetSenseData returns the sense data for the printer which reflects the
- last "Check Condition" status. This call is useful to determine the current
- state of the hardware and the result of the last executed command. A structure
- of type SCSenseData is returned which contains all state information
- available from the printer.
-
- parameters:
- senseData Pointer to a SCSenseData record in which to store the
- the current status information.
-
- returns:
- OSErr
-
- ********************************************************************************************/
- OSErr LaserSC_GetSenseData(SCSenseDataPtr senseData)
- {
- OSErr anErr;
- short scsiCommand[3];
- long cmndSz;
- long responseSz;
-
- // Validate the pointer parameter
- check(senseData != nil);
-
- // Set up the request sense SCSI command to be sent to the printer
-
- scsiCommand[0] = kSCRequestSense;
- scsiCommand[1] = kSCReserved;
- scsiCommand[2] = sizeof(SCSenseData) << 8; // High byte contains number of bytes to read
- cmndSz = 6;
-
- // Send the SCSI command to the device
-
- anErr = SendSCSICmnd((Ptr) scsiCommand, cmndSz);
- require(anErr == noErr, SendSCSICmndFails);
-
- // Now read the request sense data from the device
-
- responseSz = sizeof(SCSenseData);
-
- anErr = GetDataFromPrinter((Ptr) senseData, &responseSz, responseSz);
- require(anErr == noErr, GetDataFromPrinterFails);
-
-
- /******* Cleanup *******/
-
- GetDataFromPrinterFails:
- SendSCSICmndFails:
- return(anErr);
- }
- /* LaserSC_GetSenseData */
-
-
- /********************************************************************************************
-
- LaserSC_SetPageMargins
- function:
- LaserSC_SetPageMargins sets the page margins associated with the page buffer
- maintained by the printer. These margins should always be set when the printer
- is powered on in order to ensure that imaging doesn't occur off the paper.
- Imaging outside of the paper can reduce the life of the laser printing engine.
- These margins define the top and left margins of the imageable area of the page.
-
- This routine accepts two parameters, which represent the top margin and the
- left margin of the page. The top margin specifies the number of lines from
- the top of the page, where each line is 1/300 of an inch. The top margin
- should never be set to less that 0x76 or .197 inches. The left margin
- specifies the width of the left margin in bytes (byte = 8/300th inch).
- Incrementing or decrementing this field by one adjusts the left margin by
- 8/300th inch. The left margin should not be set to less that .197 inches.
-
- To calculate the left margins for a new paper size, keep in mind the paper is
- fed into the printer center justified. This means if the width of the paper
- decreases by .5 inches, the Left Margin would be increased by only .25 inches.
-
- parameters:
- leftMargin Left margin of the printer's page
- topMargin Top margin of the printer's page
-
- returns:
- OSErr
-
- ********************************************************************************************/
- OSErr LaserSC_SetPageMargins(short leftMargin, short topMargin)
- {
- OSErr anErr;
- short scsiCommand[3];
- long cmndSz;
- long dataSz;
- short params[2];
-
- // Validate the parameters to ensure they aren't too small
- check((topMargin >= kMinSCTopMargin) && (leftMargin >= kMinSCLeftMargin));
-
- // Set up the format SCSI command to be sent to the printer
-
- scsiCommand[0] = kSCFormatMargin;
- scsiCommand[1] = kSCReserved;
- scsiCommand[2] = 0x0400; // High byte contains the length of the parameters being sent (4 = 2 * sizeof(short))
- cmndSz = 6;
-
- // Send the SCSI command to the device
-
- anErr = SendSCSICmnd((Ptr) scsiCommand, cmndSz);
- require(anErr == noErr, SendSCSICmndFails);
-
- // Send the parameters to the set margins command on to the device
-
- params[0] = topMargin;
- params[1] = leftMargin;
- dataSz = 4;
- anErr = SendDataToPrinter((Ptr) params, dataSz, dataSz);
- require(anErr == noErr, SendDataToPrinterFails);
-
-
- /******* Cleanup *******/
-
- SendDataToPrinterFails:
- SendSCSICmndFails:
- return(anErr);
- }
- /* LaserSC_SetPageMargins */
-
-
- /********************************************************************************************
-
- LaserSC_SetPageDimensions
- function:
- LaserSC_SetPageDimensions sets the page dimensions associated with the page buffer
- maintained by the printer. These dimensions should always be set when the printer
- is powered on in order to ensure that imaging doesn't occur off the paper.
- Imaging outside of the paper can reduce the life of the laser printing engine.
- These dimensions define the number of lines per page and the number of bytes
- per line.
-
- LaserSC_SetPageDimensions accepts two parameters, the number of bytes per line
- and the number of scan lines per page. The byes per line parameter specifies
- the width of the image in bytes, where each byte represents 8/300th of an
- inch (8 pixels). This parameter must be an even number and cannot be greater
- that 304. The number of scan lines per page parameter specifies the length
- of the image in lines, where each line represents 1/300th of an inch
- (1 pixel height).
-
- These two parameters define the dimensions of an image whose top left
- corner is assumed to start at coordinate (0, 0). Positive coordinates increase
- downward and to the right. All drawing will take place within the rectangle:
- (0, 0, (Bytes per line) * 8, Number of Lines).
-
- parameters:
- bytesPerScanLine Number of bytes within each line of the page
- numScanLines Number of lines within the page
-
- returns:
- OSErr
-
- ********************************************************************************************/
- OSErr LaserSC_SetPageDimensions(short bytesPerScanLine, short numScanLines)
- {
- OSErr anErr;
- short scsiCommand[3];
- long cmndSz;
- long dataSz;
- short params[2];
-
- // Make sure the parameters are within tolerance
- check(((bytesPerScanLine % 2) == 0) && (bytesPerScanLine <= kMaxRowBytes));
-
- // Set up the format SCSI command to be sent to the printer
-
- scsiCommand[0] = kSCFormatImage;
- scsiCommand[1] = kSCReserved;
- scsiCommand[2] = 0x0400; // High byte contains the length of the parameters being sent (4 = 2 * sizeof(short))
- cmndSz = 6;
-
- // Send the SCSI command to the device
-
- anErr = SendSCSICmnd((Ptr) scsiCommand, cmndSz);
- require(anErr == noErr, SendSCSICmndFails);
-
- // Send the parameters to the set dimensions command on to the device
-
- params[0] = bytesPerScanLine;
- params[1] = numScanLines;
- dataSz = 4;
- anErr = SendDataToPrinter((Ptr) params, dataSz, dataSz);
- require(anErr == noErr, SendDataToPrinterFails);
-
-
- /******* Cleanup *******/
-
- SendDataToPrinterFails:
- SendSCSICmndFails:
- return(anErr);
- }
- /* LaserSC_SetPageDimensions */
-
-
- /********************************************************************************************
-
- LaserSC_ClearBits
- function:
- LaserSC_ClearBits will clear all bits inside the printers page buffer defined
- by the specified rectangle. This command only applies to printers with one
- megabyte of RAM installed. If this command is issued with bufferred mode in
- effect (see routine below), the clear command will return immediately, before
- clearing begins. While the area is being cleared, the printer will not be
- able to accept SCSI comands and will return a Device Busy status when
- queried.
-
- parameters:
- rectToClear Rectangle within the page buffer to clear
-
- returns:
- OSErr
-
- ********************************************************************************************/
- OSErr LaserSC_ClearBits(Rect *rectToClear)
- {
- OSErr anErr;
- short scsiCommand[3];
- long cmndSz;
- long dataSz;
- short params[4];
-
- // Set up the clear bits SCSI command to be sent to the printer
-
- scsiCommand[0] = kSCClearBits;
- scsiCommand[1] = kSCReserved;
- scsiCommand[2] = 0x0800; // High byte contains the length of the parameters being sent (8 = 4 * sizeof(short))
- cmndSz = 6;
-
- // Send the SCSI command to the device
-
- anErr = SendSCSICmnd((Ptr) scsiCommand, cmndSz);
- require(anErr == noErr, SendSCSICmndFails);
-
- // Send the parameters to the clear bits command on to the device
-
- params[0] = rectToClear->left;
- params[1] = rectToClear->top;
- params[2] = rectToClear->right;
- params[3] = rectToClear->bottom;
- dataSz = 8;
- anErr = SendDataToPrinter((Ptr) params, dataSz, dataSz);
- require(anErr == noErr, SendDataToPrinterFails);
-
- // Now we must wait until the device is no longer busy
- {
- short deviceStatus;
-
- do
- {
- // Get the latest status info from the printer
-
- anErr = LaserSC_GetDeviceStatus(&deviceStatus);
- require(anErr == noErr, LaserSC_GetDeviceStatusFails);
-
- // Let the client app have a chance to run
- anErr = GXJobIdle();
- require(anErr == noErr, JobIdleFails);
- }
- while (deviceStatus == kBusy);
- }
-
-
- /******* Cleanup *******/
-
- JobIdleFails:
- LaserSC_GetDeviceStatusFails:
- SendDataToPrinterFails:
- SendSCSICmndFails:
- return(anErr);
- }
- /* LaserSC_ClearBits */
-
-
- /********************************************************************************************
-
- LaserSC_DrawBits
- function:
- LaserSC_DrawBits transfers image data into the specified rectangular area of
- the printer's page buffer using one of several QuickDraw transfer modes. This
- command only applies to printers with one megabyte of RAM installed.
-
- The routine accepts three parameters which specify the image data to transfer,
- the rectangle within the printer's page buffer in which to image the data,
- and one of the QuickDraw transfer modes: srcCopy, srcOR, srcXOR, or srcBIC.
-
- parameters:
- imageData Pointer to the data to image
- rectToDrawIn Pointer to rectangle in which to image the data
- qdTransferMode One of the QuickDraw transfer modes srcCopy, srcOR, srcXOR,
- or srcBIC
-
- returns:
- noErr Success
- badIISCParam imageData pointer is nil
- badTransferMode invalid transfer modes passed to
-
- Any other error codes that can be returned by the Async I/O software
-
- called from:
- LaserIISC Interface Call
-
- ********************************************************************************************/
- OSErr LaserSC_DrawBits(Ptr imageData, Rect *rectToDrawIn, short numBytesPerLine, short qdTransferMode)
- {
- OSErr anErr;
- short scsiCommand[3];
- long cmndSz;
- long dataSz;
- short params[5];
- long numImageLines;
-
- // Initially validate the parameters
-
- check((imageData != nil) && (rectToDrawIn != nil));
- check((qdTransferMode == srcCopy) ||
- (qdTransferMode == srcOr) ||
- (qdTransferMode == srcXor) ||
- (qdTransferMode == srcBic));
-
- // Set up the draw bits SCSI command to be sent to the printer
-
- scsiCommand[0] = kSCDrawBits;
- scsiCommand[1] = kSCReserved;
- scsiCommand[2] = 0x0A00; // High byte contains the length of the parameters being sent (10 = 4 * sizeof(short) + sizeof(short))
- cmndSz = 6;
-
- // Send the SCSI command to the device
-
- anErr = SendSCSICmnd((Ptr) scsiCommand, cmndSz);
- require(anErr == noErr, SendSCSICmndFails);
-
- // Now set up to send the rectangle to draw in and the transfer mode, and send it
-
- params[0] = rectToDrawIn->left;
- params[1] = rectToDrawIn->top;
- params[2] = rectToDrawIn->right;
- params[3] = rectToDrawIn->bottom;
- params[4] = qdTransferMode;
- dataSz = 10;
- anErr = SendDataToPrinter((Ptr) params, dataSz, dataSz);
- require(anErr == noErr, SendDataToPrinterFails1);
-
- // Now set up to pass the bit image to the draw bits command
-
- numImageLines = rectToDrawIn->bottom - rectToDrawIn->top;
- dataSz = numImageLines * numBytesPerLine;
-
- // Now send the bitmap. We negate the last parameter to indicate the SCSI transfer should be a blind transfer.
- // Also, the SCSI transfer chunk size is set to the number of bytes in 1 scan line
-
- anErr = SendDataToPrinter(imageData, dataSz, -(numBytesPerLine));
- require(anErr == noErr, SendDataToPrinterFails2);
-
-
- /******* Cleanup *******/
-
- SendDataToPrinterFails2:
- SendDataToPrinterFails1:
- SendSCSICmndFails:
- return(anErr);
- }
- /* LaserSC_DrawBits */
-
-
- /********************************************************************************************
-
- LaserSC_PrintPage
- function:
- LaserSC_PrintPage prints the current contents of the printer's page buffer.
- As soon as the SCSI print command returns control to this routine, it
- returns to the caller. If the printer is set for buffered mode, then when
- this routine returns the printer may still be busy printing the page. Thus,
- if you're using the printer in buffered mode, you must make sure that the
- printer is no longer busy before you start sending data for the next page.
-
- The continuousPrint parameter can be used to attain the 8 page per minute
- rating of the IISC engine. Set this parameter to true to attain the improved
- rating. It should only be set true if the next print command will be issued
- in less than 7.4 seconds (8.7 for Legal paper).
-
- Setting clearPage to true causes the image area in the printers memory to be
- cleared as the page is being printed. This substantially reduces the amount
- of time a client may wait for the printers page buffer to clear.
-
- parameters:
- continuousPrint T => print at 8 page per minute rate; F => print normal rate
- clearPage T => clear printers page buffer while printing; F => don't clear buffer
-
- returns:
- OSErr
-
- ********************************************************************************************/
- OSErr LaserSC_PrintPage(Boolean continuousPrint, Boolean clearPage)
- {
- OSErr anErr;
- short scsiCommand[3];
- long cmndSz;
-
- // Set up the print command to be sent to the printer
-
- scsiCommand[0] = kSCPrint;
- scsiCommand[1] = kSCReserved;
- scsiCommand[2] = kSCReserved;
-
- if (continuousPrint) // T => Modify command to indicate 8 page per minute printing
- scsiCommand[2] += kPrintContinuous;
-
- if (clearPage) // T => Clear page while we print
- scsiCommand[2] += kClearWhilePrinting;
-
- scsiCommand[2] += kPrintFromSCRam; // Always print from the printers RAM
- cmndSz = 6;
-
- // Send the SCSI command to the device
-
- anErr = SendSCSICmnd((Ptr) scsiCommand, cmndSz);
- require(anErr == noErr, SendSCSICmndFails);
-
-
- /******* Cleanup *******/
-
- SendSCSICmndFails:
- return(anErr);
- }
- /* LaserSC_PrintPage */
-
-
- /********************************************************************************************
-
- LaserSC_QueryPrinter
- function:
- LaserSC_QueryPrinter returns specific information about the printer (e.g. paper
- size, vendor, etc.). This call is useful to determine configuration information
- about the printer. A structure of type SCInquiryData is returned which
- contains all configuration information available from the printer.
-
- parameters:
- inquiryData Pointer to a SCInquiryData record in which to store the
- the configuration information.
- querySize amount of data (bytes) that should be read from device
-
- returns:
- OSErr
-
- ********************************************************************************************/
- OSErr LaserSC_QueryPrinter(SCInquiryDataPtr inquiryData, char querySize)
- {
- OSErr anErr;
- short scsiCommand[3];
- long cmndSz;
- long dataSz;
-
- // Set up the inquiry command to be sent to the printer as the write portion
- // of a status command.
-
- scsiCommand[0] = kSCInquiry;
- scsiCommand[1] = kSCReserved;
- scsiCommand[2] = querySize << 8; // Number of inquiry bytes to return
- cmndSz = 6;
-
- // Send the SCSI command to the device
-
- anErr = SendSCSICmnd((Ptr) scsiCommand, cmndSz);
- require(anErr == noErr, SendSCSICmndFails);
-
- // Now read the query data from the device
-
- dataSz = querySize;
-
- anErr = GetDataFromPrinter((Ptr) inquiryData, &dataSz, dataSz);
- require(anErr == noErr, GetDataFromPrinterFails);
-
-
- /******* Cleanup *******/
-
- GetDataFromPrinterFails:
- SendSCSICmndFails:
- return(anErr);
- }/* LaserSC_QueryPrinter */
-
-
- /********************************************************************************************
-
- LaserSC_SetBuffandFeedMode
- function:
- LaserSC_SetBuffandFeedMode is used to change the manual feed and bufferred mode
- settings of the printer. Setting manualFeed to true informs the printer that
- paper will be fed manually as opposed to automatically from the cassette.
- Setting bufferedMode to true causes the print from printer RAM and clear bits
- commands to return immediately, without waiting for the command to complete.
- If buffered mode is selected, the printer will return a device busy status
- while the operation completes.
-
- parameters:
- manualFeed T => pages will be manually fed into the printer; F => cassette fed
- bufferedMode T => Don't wait for clear bits and print RAM commands to complete;
- F => wait for them to complete.
-
- returns:
- OSErr
-
- ********************************************************************************************/
- OSErr LaserSC_SetBuffandFeedMode(Boolean manualFeed, Boolean bufferedMode)
- {
- OSErr anErr;
- short scsiCommand[3];
- long cmndSz;
- long dataSz;
- char params[12];
- short i;
-
- // Set up the mode select SCSI command to be sent to the printer
-
- scsiCommand[0] = kSCModeSelect;
- scsiCommand[1] = kSCReserved;
- scsiCommand[2] = 0x0C00; // High bytes specifies # of bytes being sent to the printer
- cmndSz = 6;
-
- // Send the SCSI command to the device
-
- anErr = SendSCSICmnd((Ptr) scsiCommand, cmndSz);
- require(anErr == noErr, SendSCSICmndFails);
-
- // Now set up the mode select parameters to be passed to the printer
-
- for (i = 0; i <= 11; i++) // Zero all twelve bytes initially
- params[i] = 0;
-
- if (manualFeed) // T => Set for manual feed mode
- params[kFeed] = kManual;
-
- if (bufferedMode) // T => Set for buffered mode
- params[kBuffered] = kBufferedMode;
-
- // Now send the parameters to the printer
-
- dataSz = 12;
- anErr = SendDataToPrinter(params, dataSz, dataSz);
- require(anErr == noErr, SendDataToPrinterFails);
-
- /******* CLean-up *******/
-
- SendDataToPrinterFails:
- SendSCSICmndFails:
- return(anErr);
- }
- /* LaserSC_SetBuffandFeedMode */
-
-
- /********************************************************************************************
-
- LaserSC_GetTimeoutForSCSICmnd
- function:
- This routine returns the timeout that should be used in the call to SCSIComplete
- when the specified printer command is forced to complete.
-
- parameters:
- scsiCmnd SCSI command to be issued to the printer (generated by another
- LaserSCIntf.c interface routine).
-
- returns:
- long timeout (in ticks) to use for the SCSIComplete call
-
- ********************************************************************************************/
- long LaserSC_GetTimeoutForSCSICmnd(short scsiCmnd)
- {
- long timeout;
-
- switch ( scsiCmnd )
- {
- case kSCPrinterReady:
- case kSCResetPrinter:
- case kSCRequestSense:
- case kSCFormatMargin:
- case kSCFormatImage:
- case kSCInquiry:
- case kSCDrawBits:
- case kSCModeSelect:
- case kSCReserveUnit:
- case kSCReleaseUnit:
- case kSCModeSense:
- timeout = 240;
- break;
-
- case kSCClearBits:
- timeout = 480;
- break;
-
- case kSCDownLoadCode:
- case kSCPrint:
- timeout = 4800;
- break;
- }
-
- return(timeout);
- }
- /* LaserSC_GetTimeoutForSCSICmnd */
-